package com.ship.dispatch.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ship.common.business.service.impl.BaseServiceImpl;
import com.ship.common.core.base.Page;
import com.ship.common.core.domain.R;
import com.ship.common.core.exception.BusException;
import com.ship.common.core.web.domain.BaseResultCode;
import com.ship.common.core.web.domain.JsonResult;
import com.ship.dispatch.bean.TzFuelDelivery;
import com.ship.dispatch.bean.TzFuelRecord;
import com.ship.dispatch.bean.TzFuelReport;
import com.ship.dispatch.bo.TzFuelRecordLsmgoBo;
import com.ship.dispatch.bo.TzFuelRecordVlsfoBo;
import com.ship.dispatch.service.TzFuelDeliveryService;
import com.ship.dispatch.service.TzFuelRecordService;
import com.ship.dispatch.mapper.TzFuelRecordMapper;
import com.ship.dispatch.service.TzFuelReportService;
import com.ship.system.api.RemoteFileService;
import com.ship.system.api.domain.SysFile;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
* @author zhangyh
* @description 针对表【tz_fuel_record(燃油台账燃油记录信息)】的数据库操作Service实现
* @createDate 2024-06-17 11:31:48
*/
@Service
public class TzFuelRecordServiceImpl extends BaseServiceImpl<TzFuelRecordMapper, TzFuelRecord>
    implements TzFuelRecordService{

    @Resource
    private TzFuelReportService tzFuelReportService;

    @Resource
    private TzFuelDeliveryService tzFuelDeliveryService;

    @Resource
    private RemoteFileService remoteFileService;

    @Override
    public void dataTransfer(TzFuelRecord dto) {
        dto.setEventType("午报");
        if(StringUtils.isNotBlank(dto.getMessageDate())){
            String recordDate = dto.getMessageDate();
            //判断当前船只午报时间是否有交还船记录
            TzFuelDelivery delivery =  tzFuelDeliveryService.getBaseMapper().selectOne(
                    new LambdaQueryWrapper<TzFuelDelivery>()
                            .eq(TzFuelDelivery::getShipName,dto.getShipName())
                            .ge(TzFuelDelivery::getDeliveryTime,recordDate+" 00:00:00")
                            .le(TzFuelDelivery::getDeliveryTime,recordDate+" 23:59:59")
                            .last("limit 1")
            );
            /**
             * 若为租入长期船-还船结算、租入短期船-还船结算、船舶租出交船结算，船上剩余量置为0，消耗量为全部
             * 若为租入长期船-交船结算、租入短期船-交船结算、船舶租出-还船结算，船上剩余量为交船记录时的量。消耗量为0，次日再进行累计计算
             */
            if(delivery != null && !StringUtils.equals("内部转租",delivery.getContractType())){
                dto.setEventType(delivery.getContractType()+"-"+delivery.getEventType());
                if(delivery.getDeliveryType().intValue() == 1){
                    if(StringUtils.equals("租入长期船",delivery.getContractType()) || StringUtils.equals("租入短期船",delivery.getContractType())){
                        dto.setVlsfoLeaveValue(delivery.getVlsfo());
                        dto.setVlsfoUseValue(BigDecimal.ZERO);
                        dto.setLsmgoLeaveValue(delivery.getLsmgo());
                        dto.setLsmgoUseValue(BigDecimal.ZERO);
                    }else{
                        dto.setVlsfoLeaveValue(BigDecimal.ZERO);
                        dto.setVlsfoUseValue(delivery.getVlsfo());
                        dto.setLsmgoLeaveValue(BigDecimal.ZERO);
                        dto.setLsmgoUseValue(delivery.getLsmgo());
                    }
                }else{
                    if(StringUtils.equals("租入长期船",delivery.getContractType()) || StringUtils.equals("租入短期船",delivery.getContractType())){
                        dto.setVlsfoLeaveValue(BigDecimal.ZERO);
                        dto.setVlsfoUseValue(delivery.getVlsfo());
                        dto.setLsmgoLeaveValue(BigDecimal.ZERO);
                        dto.setLsmgoUseValue(delivery.getLsmgo());
                    }else{
                        dto.setVlsfoLeaveValue(delivery.getVlsfo());
                        dto.setVlsfoUseValue(BigDecimal.ZERO);
                        dto.setLsmgoLeaveValue(delivery.getLsmgo());
                        dto.setLsmgoUseValue(BigDecimal.ZERO);
                    }
                }
            }
        }

        //然后台账计算逻辑
        if(dto.getVlsfoDayLeave() != null){
            //获取交还船时间之前的三条记录
            List<TzFuelReport> fuelReports = tzFuelReportService.getBaseMapper().selectList(
                    new LambdaQueryWrapper<TzFuelReport>()
                            .eq(TzFuelReport::getShipName,dto.getShipName())
                            .gt(TzFuelReport::getVlsfoValue,0)
                            .le(TzFuelReport::getFuelTime,dto.getMessageDate())
                            .orderByDesc(TzFuelReport::getFuelTime)
                            .last("limit 3")
            );
            BigDecimal dataCount = dto.getVlsfoDayLeave();
            BigDecimal vlsValue = BigDecimal.ZERO;
            for (TzFuelReport fuelReport : fuelReports) {
                if(fuelReport.getVlsfoValue() != null){
                    vlsValue = vlsValue.add(fuelReport.getVlsfoValue());
                }
            }
            if(dataCount.compareTo(vlsValue) < 0){
                if(fuelReports.size() == 1){
                    TzFuelReport fuelReport = fuelReports.get(0);
                    dto.setVlsfoOne(dataCount);
                    dto.setVlsfoOnePrice(fuelReport.getVlsfoPrice());
                    if(dto.getVlsfoOne() != null && dto.getVlsfoOnePrice() != null){
                        BigDecimal settlement = dto.getVlsfoOne().multiply(dto.getVlsfoOnePrice());
                        dto.setVlsfoLeaveValue(settlement);
                    }
                    if(dto.getVlsfoDayUse() != null && dto.getVlsfoOnePrice() != null){
                        BigDecimal useValue = dto.getVlsfoDayUse().multiply(dto.getVlsfoOnePrice());
                        dto.setVlsfoUseValue(useValue);
                    }
                }else if(fuelReports.size() == 2){
                    TzFuelReport fuelReport = fuelReports.get(0);
                    if(dataCount.compareTo(fuelReport.getVlsfoValue()) < 1){
                        dto.setVlsfoOne(dataCount);
                        dto.setVlsfoOnePrice(fuelReport.getVlsfoPrice());
                        if(dto.getVlsfoOne() != null && dto.getVlsfoOnePrice() != null){
                            BigDecimal settlement = dto.getVlsfoOne().multiply(dto.getVlsfoOnePrice());
                            dto.setVlsfoLeaveValue(settlement);
                        }
                        if(dto.getVlsfoDayUse() != null && dto.getVlsfoOnePrice() != null){
                            BigDecimal useValue = dto.getVlsfoDayUse().multiply(dto.getVlsfoOnePrice());
                            dto.setVlsfoUseValue(useValue);
                        }
                    }else{
                        BigDecimal lessValue = dataCount.subtract(fuelReport.getVlsfoValue());
                        TzFuelReport fuelReport1 = fuelReports.get(1);
                        dto.setVlsfoOne(lessValue);
                        dto.setVlsfoOnePrice(fuelReport1.getVlsfoPrice());
                        dto.setVlsfoTwo(fuelReport.getVlsfoValue());
                        dto.setVlsfoTwoPrice(fuelReport.getVlsfoPrice());

                        BigDecimal settlement = BigDecimal.ZERO;
                        if(dto.getVlsfoOne() != null && dto.getVlsfoOnePrice() != null){
                            settlement = settlement.add(dto.getVlsfoOne().multiply(dto.getVlsfoOnePrice()));
                        }
                        if(dto.getVlsfoTwo() != null && dto.getVlsfoTwoPrice() != null){
                            settlement = settlement.add(dto.getVlsfoTwo().multiply(dto.getVlsfoTwoPrice()));
                        }
                        if(dto.getVlsfoDayUse() != null && dto.getVlsfoOnePrice() != null){
                            BigDecimal useValue = dto.getVlsfoDayUse().multiply(dto.getVlsfoOnePrice());
                            dto.setVlsfoUseValue(useValue);
                        }
                        dto.setVlsfoLeaveValue(settlement);
                    }
                }else{
                    TzFuelReport fuelReport = fuelReports.get(0);
                    if(dataCount.compareTo(fuelReport.getVlsfoValue()) < 1){
                        dto.setVlsfoOne(dataCount);
                        dto.setVlsfoOnePrice(fuelReport.getVlsfoPrice());
                        if(dto.getVlsfoOne() != null && dto.getVlsfoOnePrice() != null){
                            BigDecimal settlement = dto.getVlsfoOne().multiply(dto.getVlsfoOnePrice());
                            dto.setVlsfoLeaveValue(settlement);
                        }
                        if(dto.getVlsfoDayUse() != null && dto.getVlsfoOnePrice() != null){
                            BigDecimal useValue = dto.getVlsfoDayUse().multiply(dto.getVlsfoOnePrice());
                            dto.setVlsfoUseValue(useValue);
                        }
                    }else{
                        BigDecimal lessValue = dataCount.subtract(fuelReport.getVlsfoValue());
                        TzFuelReport fuelReport1 = fuelReports.get(1);
                        if(lessValue.compareTo(fuelReport1.getVlsfoValue()) < 1){
                            dto.setVlsfoOne(lessValue);
                            dto.setVlsfoOnePrice(fuelReport1.getVlsfoPrice());
                            dto.setVlsfoTwo(fuelReport.getVlsfoValue());
                            dto.setVlsfoTwoPrice(fuelReport.getVlsfoPrice());
                            BigDecimal settlement = BigDecimal.ZERO;
                            if(dto.getVlsfoOne() != null && dto.getVlsfoOnePrice() != null){
                                settlement = settlement.add(dto.getVlsfoOne().multiply(dto.getVlsfoOnePrice()));
                            }
                            if(dto.getVlsfoTwo() != null && dto.getVlsfoTwoPrice() != null){
                                settlement = settlement.add(dto.getVlsfoTwo().multiply(dto.getVlsfoTwoPrice()));
                            }
                            if(dto.getVlsfoDayUse() != null && dto.getVlsfoOnePrice() != null){
                                BigDecimal useValue = dto.getVlsfoDayUse().multiply(dto.getVlsfoOnePrice());
                                dto.setVlsfoUseValue(useValue);
                            }
                            dto.setVlsfoLeaveValue(settlement);
                        }else{
                            BigDecimal lessValue2 = lessValue.subtract(fuelReport1.getVlsfoValue());
                            TzFuelReport fuelReport2 = fuelReports.get(2);
                            dto.setVlsfoOne(lessValue2);
                            dto.setVlsfoOnePrice(fuelReport2.getVlsfoPrice());
                            dto.setVlsfoTwo(fuelReport1.getVlsfoValue());
                            dto.setVlsfoTwoPrice(fuelReport1.getVlsfoPrice());
                            dto.setVlsfoThree(fuelReport.getVlsfoValue());
                            dto.setVlsfoThreePrice(fuelReport.getVlsfoPrice());

                            BigDecimal settlement = BigDecimal.ZERO;
                            if(dto.getVlsfoOne() != null && dto.getVlsfoOnePrice() != null){
                                settlement = settlement.add(dto.getVlsfoOne().multiply(dto.getVlsfoOnePrice()));
                            }
                            if(dto.getVlsfoTwo() != null && dto.getVlsfoTwoPrice() != null){
                                settlement = settlement.add(dto.getVlsfoTwo().multiply(dto.getVlsfoTwoPrice()));
                            }
                            if(dto.getVlsfoThree() != null && dto.getVlsfoThreePrice() != null){
                                settlement = settlement.add(dto.getVlsfoThree().multiply(dto.getVlsfoThreePrice()));
                            }
                            if(dto.getVlsfoDayUse() != null && dto.getVlsfoOnePrice() != null){
                                BigDecimal useValue = dto.getVlsfoDayUse().multiply(dto.getVlsfoOnePrice());
                                dto.setVlsfoUseValue(useValue);
                            }
                            dto.setVlsfoLeaveValue(settlement);
                        }
                    }
                }
            }
        }
        if(dto.getLsmgoDayLeave() != null){
            //获取交还船时间之前的三条记录
            List<TzFuelReport> fuelReports = tzFuelReportService.getBaseMapper().selectList(
                    new LambdaQueryWrapper<TzFuelReport>()
                            .eq(TzFuelReport::getShipName,dto.getShipName())
                            .gt(TzFuelReport::getLsmgoValue,0)
                            .le(TzFuelReport::getFuelTime,dto.getMessageDate())
                            .orderByDesc(TzFuelReport::getFuelTime)
                            .last("limit 3")
            );
            BigDecimal dataCount = dto.getLsmgoDayLeave();
            BigDecimal lsmValue = BigDecimal.ZERO;
            for (TzFuelReport fuelReport : fuelReports) {
                if(fuelReport.getLsmgoValue() != null){
                    lsmValue = lsmValue.add(fuelReport.getLsmgoValue());
                }
            }
            if(dataCount.compareTo(lsmValue) < 0){
                if(fuelReports.size() == 1){
                    TzFuelReport fuelReport = fuelReports.get(0);
                    dto.setLsmgoOne(dataCount);
                    dto.setLsmgoOnePrice(fuelReport.getLsmgoPrice());

                    if(dto.getLsmgoOne() != null && dto.getLsmgoOnePrice() != null){
                        BigDecimal settlement = dto.getLsmgoOne().multiply(dto.getLsmgoOnePrice());
                        dto.setLsmgoLeaveValue(settlement);
                    }
                    if(dto.getLsmgoDayUse() != null && dto.getLsmgoOnePrice() != null){
                        BigDecimal useValue = dto.getLsmgoDayUse().multiply(dto.getLsmgoOnePrice());
                        dto.setLsmgoUseValue(useValue);
                    }
                }else if(fuelReports.size() == 2){
                    TzFuelReport fuelReport = fuelReports.get(0);
                    if(dataCount.compareTo(fuelReport.getLsmgoValue()) < 1){
                        dto.setLsmgoOne(dataCount);
                        dto.setLsmgoOnePrice(fuelReport.getLsmgoPrice());
                        if(dto.getLsmgoOne() != null && dto.getLsmgoOnePrice() != null){
                            BigDecimal settlement = dto.getLsmgoOne().multiply(dto.getLsmgoOnePrice());
                            dto.setLsmgoLeaveValue(settlement);
                        }
                        if(dto.getLsmgoDayUse() != null && dto.getLsmgoOnePrice() != null){
                            BigDecimal useValue = dto.getLsmgoDayUse().multiply(dto.getLsmgoOnePrice());
                            dto.setLsmgoUseValue(useValue);
                        }
                    }else{
                        BigDecimal lessValue = dataCount.subtract(fuelReport.getLsmgoValue());
                        TzFuelReport fuelReport1 = fuelReports.get(1);
                        dto.setLsmgoOne(lessValue);
                        dto.setLsmgoOnePrice(fuelReport1.getLsmgoPrice());
                        dto.setLsmgoTwo(fuelReport.getLsmgoValue());
                        dto.setLsmgoTwoPrice(fuelReport.getLsmgoPrice());

                        BigDecimal settlement = BigDecimal.ZERO;
                        if(dto.getLsmgoOne() != null && dto.getLsmgoOnePrice() != null){
                            settlement = settlement.add(dto.getLsmgoOne().multiply(dto.getLsmgoOnePrice()));
                        }
                        if(dto.getLsmgoTwo() != null && dto.getLsmgoTwoPrice() != null){
                            settlement = settlement.add(dto.getLsmgoTwo().multiply(dto.getLsmgoTwoPrice()));
                        }
                        if(dto.getLsmgoDayUse() != null && dto.getLsmgoOnePrice() != null){
                            BigDecimal useValue = dto.getLsmgoDayUse().multiply(dto.getLsmgoOnePrice());
                            dto.setLsmgoUseValue(useValue);
                        }

                        dto.setLsmgoLeaveValue(settlement);
                    }
                }else{
                    TzFuelReport fuelReport = fuelReports.get(0);
                    if(dataCount.compareTo(fuelReport.getLsmgoValue()) < 1){
                        dto.setLsmgoOne(dataCount);
                        dto.setLsmgoOnePrice(fuelReport.getLsmgoPrice());
                        if(dto.getLsmgoOne() != null && dto.getLsmgoOnePrice() != null){
                            BigDecimal settlement = dto.getLsmgoOne().multiply(dto.getLsmgoOnePrice());
                            dto.setLsmgoLeaveValue(settlement);
                        }
                        if(dto.getLsmgoDayUse() != null && dto.getLsmgoOnePrice() != null){
                            BigDecimal useValue = dto.getLsmgoDayUse().multiply(dto.getLsmgoOnePrice());
                            dto.setLsmgoUseValue(useValue);
                        }
                    }else{
                        BigDecimal lessValue = dataCount.subtract(fuelReport.getLsmgoValue());
                        TzFuelReport fuelReport1 = fuelReports.get(1);
                        if(lessValue.compareTo(fuelReport1.getLsmgoValue()) < 1){
                            dto.setLsmgoOne(lessValue);
                            dto.setLsmgoOnePrice(fuelReport1.getLsmgoPrice());
                            dto.setLsmgoTwo(fuelReport.getLsmgoValue());
                            dto.setLsmgoTwoPrice(fuelReport.getLsmgoPrice());
                            BigDecimal settlement = BigDecimal.ZERO;
                            if(dto.getLsmgoOne() != null && dto.getLsmgoOnePrice() != null){
                                settlement = settlement.add(dto.getLsmgoOne().multiply(dto.getLsmgoOnePrice()));
                            }
                            if(dto.getLsmgoTwo() != null && dto.getLsmgoTwoPrice() != null){
                                settlement = settlement.add(dto.getLsmgoTwo().multiply(dto.getLsmgoTwoPrice()));
                            }
                            if(dto.getLsmgoDayUse() != null && dto.getLsmgoOnePrice() != null){
                                BigDecimal useValue = dto.getLsmgoDayUse().multiply(dto.getLsmgoOnePrice());
                                dto.setLsmgoUseValue(useValue);
                            }
                            dto.setLsmgoLeaveValue(settlement);
                        }else{
                            BigDecimal lessValue2 = lessValue.subtract(fuelReport1.getLsmgoValue());
                            TzFuelReport fuelReport2 = fuelReports.get(2);
                            dto.setLsmgoOne(lessValue2);
                            dto.setLsmgoOnePrice(fuelReport2.getLsmgoPrice());
                            dto.setLsmgoTwo(fuelReport1.getLsmgoValue());
                            dto.setLsmgoTwoPrice(fuelReport1.getLsmgoPrice());
                            dto.setLsmgoThree(fuelReport.getLsmgoValue());
                            dto.setLsmgoThreePrice(fuelReport.getLsmgoPrice());

                            BigDecimal settlement = BigDecimal.ZERO;
                            if(dto.getLsmgoOne() != null && dto.getLsmgoOnePrice() != null){
                                settlement = settlement.add(dto.getLsmgoOne().multiply(dto.getLsmgoOnePrice()));
                            }
                            if(dto.getLsmgoTwo() != null && dto.getLsmgoTwoPrice() != null){
                                settlement = settlement.add(dto.getLsmgoTwo().multiply(dto.getLsmgoTwoPrice()));
                            }
                            if(dto.getLsmgoThree() != null && dto.getLsmgoThreePrice() != null){
                                settlement = settlement.add(dto.getLsmgoThree().multiply(dto.getLsmgoThreePrice()));
                            }
                            if(dto.getLsmgoDayUse() != null && dto.getLsmgoOnePrice() != null){
                                BigDecimal useValue = dto.getLsmgoDayUse().multiply(dto.getLsmgoOnePrice());
                                dto.setLsmgoUseValue(useValue);
                            }
                            dto.setLsmgoLeaveValue(settlement);
                        }
                    }
                }
            }
        }

        if(dto.getOperaType() != null && dto.getOperaType().intValue() == 2){
            TzFuelRecord old = this.baseMapper.selectOne(
                    new LambdaQueryWrapper<TzFuelRecord>()
                    .eq(TzFuelRecord::getShipName,dto.getShipName())
                    .eq(TzFuelRecord::getMessageDate,dto.getMessageDate())
                    .last("limit 1")
            );
            if(old == null){
                this.baseMapper.insert(dto);
            }else{
                this.baseMapper.updateById(dto);
            }
        }else{
            this.baseMapper.insert(dto);
        }
    }

    @Override
    public JsonResult<Page<TzFuelRecord>> getPage(TzFuelRecord dto) {
        dto.setOrderField("message_date");
        QueryWrapper wrapper = new QueryWrapper();
//        if(dto.getSelectType() != null && dto.getSelectType().intValue() == 1){
//            wrapper.gt("vlsfo_day_leave",0);
//        }else{
//            wrapper.gt("lsmgo_day_leave",0);
//        }
        Page<TzFuelRecord> resultPage = this.page(dto,wrapper);
        return JsonResult.success(resultPage);
    }

    @Override
    public JsonResult dataExport(TzFuelRecord dto) throws IOException {
        dto.setOrderField("message_date");
        QueryWrapper wrapper = new QueryWrapper();
        String type = "LSMGO";
        if(dto.getSelectType() != null && dto.getSelectType().intValue() == 1){
//            wrapper.gt("vlsfo_day_leave",0);
            type = "VLSFO";
        }else{
//            wrapper.gt("lsmgo_day_leave",0);
        }
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if(dto.getIds() != null && dto.getIds().size() > 0){
            queryWrapper.in("id",dto.getIds());
        }
        List<TzFuelRecord> dataList = this.pageExportList(dto,queryWrapper,new LinkedList<>());
        String shipName = "";
        if(dataList.size() > 0){
            shipName = dataList.get(0).getShipName()+"-";
        }
        String fileName = shipName+"燃油记录-"+type+"-"+ DateFormatUtils.format(new Date(), "yyyy-MM-dd");
        //创建临时文件
        File tempFileExcel = new File(fileName+".xlsx");

        if(dto.getSelectType() != null && dto.getSelectType().intValue() == 1){
            List<TzFuelRecordVlsfoBo> boList = new LinkedList<>();
            for (TzFuelRecord fuelRecord : dataList) {
                TzFuelRecordVlsfoBo vlsfoBo = new TzFuelRecordVlsfoBo();
                vlsfoBo.setShipName(fuelRecord.getShipName());
                vlsfoBo.setMessageDate(fuelRecord.getMessageDate());
                vlsfoBo.setVlsfoDayLeaveStr(fuelRecord.getVlsfoDayLeaveStr());
                vlsfoBo.setVlsfoDayUseStr(fuelRecord.getVlsfoDayUseStr());
                vlsfoBo.setVlsfoOneStr(fuelRecord.getVlsfoOneStr());
                vlsfoBo.setVlsfoOnePriceStr(fuelRecord.getVlsfoOnePriceStr());
                vlsfoBo.setVlsfoTwoStr(fuelRecord.getVlsfoTwoStr());
                vlsfoBo.setVlsfoTwoPriceStr(fuelRecord.getVlsfoTwoPriceStr());
                vlsfoBo.setVlsfoThreeStr(fuelRecord.getVlsfoThreeStr());
                vlsfoBo.setVlsfoThreePriceStr(fuelRecord.getVlsfoThreePriceStr());
                vlsfoBo.setVlsfoLeaveValueStr(fuelRecord.getVlsfoLeaveValueStr());
                vlsfoBo.setVlsfoUseValueStr(fuelRecord.getVlsfoUseValueStr());
                vlsfoBo.setEventType(fuelRecord.getEventType());
                boList.add(vlsfoBo);
            }
            EasyExcel.write(fileName+".xlsx", TzFuelRecordVlsfoBo.class).sheet("燃油记录").doWrite(boList);
        }else{
            List<TzFuelRecordLsmgoBo> boList = new LinkedList<>();
            for (TzFuelRecord fuelRecord : dataList) {
                TzFuelRecordLsmgoBo lsmgoBo = new TzFuelRecordLsmgoBo();
                lsmgoBo.setShipName(fuelRecord.getShipName());
                lsmgoBo.setMessageDate(fuelRecord.getMessageDate());
                lsmgoBo.setLsmgoDayLeaveStr(fuelRecord.getLsmgoDayLeaveStr());
                lsmgoBo.setLsmgoDayUseStr(fuelRecord.getLsmgoDayUseStr());
                lsmgoBo.setLsmgoOneStr(fuelRecord.getLsmgoOneStr());
                lsmgoBo.setLsmgoOnePriceStr(fuelRecord.getLsmgoOnePriceStr());
                lsmgoBo.setLsmgoTwoStr(fuelRecord.getLsmgoTwoStr());
                lsmgoBo.setLsmgoTwoPriceStr(fuelRecord.getLsmgoTwoPriceStr());
                lsmgoBo.setLsmgoThreeStr(fuelRecord.getLsmgoThreeStr());
                lsmgoBo.setLsmgoThreePriceStr(fuelRecord.getLsmgoThreePriceStr());
                lsmgoBo.setLsmgoLeaveValueStr(fuelRecord.getLsmgoLeaveValueStr());
                lsmgoBo.setLsmgoUseValueStr(fuelRecord.getLsmgoUseValueStr());
                lsmgoBo.setEventType(fuelRecord.getEventType());
                boList.add(lsmgoBo);
            }
            EasyExcel.write(fileName+".xlsx", TzFuelRecordLsmgoBo.class).sheet("燃油记录").doWrite(boList);
        }
        FileInputStream input = new FileInputStream(tempFileExcel);
        MultipartFile multipartFile = new MockMultipartFile("file",tempFileExcel.getName() , "application/octet-stream", input);
        R<SysFile> result1 = remoteFileService.upload(multipartFile);
        if(result1.getCode() != R.SUCCESS){
            tempFileExcel.delete();
            throw new BusException("文件服务器连接失败", BaseResultCode.GENERAL_ERROR);
        }
        String urls = result1.getData().getHttpsUrl();
        tempFileExcel.delete();
        return JsonResult.success(urls);
    }
}




